﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace Utils
{
    public static class MessageBox
    {
        public static void ShowMessage(string MessageText, Page MyPage)
        {
            MyPage.ClientScript.RegisterStartupScript(MyPage.GetType(),
                "MessageBox", "alert('" + MessageText.Replace("'", "\'") + "');", true);
        }

        // Tạo confirm cho Button
        public static void ConfirmButton(Button btn, String content)
        {
            btn.Attributes.Add("onclick", "return confirm('" + content + "');");
        }

        // Lấy già trị trong GridView theo cột
        public static String GetValueGridView(GridView grid, int col, GridViewSelectEventArgs e)
        {
            return grid.Rows[e.NewSelectedIndex].Cells[col].Text.Replace("&nbsp;", "");
        }

        // Lấy DataKey (khóa chính) trong GridView
        public static String GetDataKey(GridView grid, GridViewDeleteEventArgs e)
        {
            return grid.DataKeys[e.RowIndex].Value.ToString();
        }

        // confirm khi xóa dữ liệu trong gridview
        public static void ConfirmDelete(String content, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.DataRow) return;

            int lastCellIndex = e.Row.Cells.Count - 1;
            LinkButton deleteButton = (LinkButton)e.Row.Cells[lastCellIndex].Controls[0];
            deleteButton.OnClientClick =
              "if (!window.confirm('" + content + "')) return false;";
        }
    }
}
